<template>
  <div class="container">
        <div class="addDepartment">
            <div class="panel">
                <div class="i-cell i-input">
                    <div class="i-input-title">法定全称：</div>
                    <input class='i-input-input' type="text" v-model="organize.fullName" placeholder="请输入营业执照名称">
                </div>
                <div class="i-cell i-input">
                    <div class="i-input-title">简 称：</div>
                    <input class='i-input-input' type="text" v-model="organize.shortName" placeholder="请输入简称">
                </div>
                <div class="i-cell i-cell-access" @click="chooseDep">
                    <div class="i-input-bd">
                        <div class="i-cell-text">选择上级公司</div>
                    </div>
                    <div class="i-cell-ft">{{addSubChooseInfo.F_FullName}}</div>
                </div>
                <div class="i-cell i-input">
                    <div class="i-input-title">主管姓名:</div>
                    <input class='i-input-input' type="text" v-model="organize.manager" placeholder="请输入主管姓名" >
                </div>
                <div class="i-cell i-input">
                    <div class="i-input-title">手机号码:</div>
                    <input class='i-input-input' type="number" placeholder="请输入手机号码" v-model="organize.mobilePhone">
                </div>
                <div class="i-cell i-input">
                    <div class="i-input-title">邮 箱：</div>
                    <input class='i-input-input' type="text" placeholder="请输入邮箱" v-model="organize.email">
                </div>
                <div class="i-cell i-input">
                    <div class="i-input-title">初始密码：</div>
                    <input class='i-input-input' type="text" v-model="organize.password" placeholder="请输入初始密码">
                </div>
                <!-- <i-input v-model="organize.fullName" @change="handlefullNameChange" title="法定全称：" autofocus placeholder="请输入营业执照名称" />
                <i-input v-model="organize.shortName" @change="handleshortNameChange" title="简         称：" placeholder="请输入简称" />
                <i-cell title="选择上级公司" v-model="addSubChooseInfo.F_FullName" is-link url='/pages/center/chooseDepartment?type=addSub'></i-cell>
                <i-input v-model="organize.manager" @change="handlemanagerChange" title="主管姓名" placeholder="请输入主管姓名" />
                <i-input v-model="organize.mobilePhone" @change="handlemobilePhoneChange" title="手机号码" type="number" placeholder="请输入手机号码"/>
                <i-input v-model="organize.email" @change="handleemailChange" title="邮         箱：" placeholder="请输入邮箱" />
                <i-input v-model="organize.password" @change="handlepasswordChange" title="初始密码：" placeholder="请输入初始密码" /> -->
            </div>

            <buttomBtn title="保存" @handleClick='handleClick'></buttomBtn>
        </div>
  </div>
</template>

<script>
import buttomBtn from '@/components/Bbutton'
import { mapState } from 'vuex'
import { addOrganize } from 'api/api'
export default {
    data () {
        return {
            organize: {
                'parentId': '',
                'fullName': '',
                'shortName': '',
                'code': '',
                'manager': '',
                'telePhone': '',
                'mobilePhone': '',
                'weChat': '',
                'fax': '',
                'email': '',
                'address': '',
                'descriptions': '',
                'password': ''
            }
        }
    },

    components: {
        buttomBtn
    },

    methods: {
        handleClick () {
            if (this.addSubChooseInfo === {}) {
                wx.showToast({
                    title: '请选择上级公司',
                    icon: 'error',
                    mask: true
                })
                return
            }
            if (!this.organize.shortName) {
                wx.showToast({
                    title: '请输入简称',
                    icon: 'none',
                    mask: true,
                    duration: 1000
                })
                return
            }
            if (!this.organize.manager) {
                wx.showToast({
                    title: '请输入主管姓名',
                    icon: 'none',
                    mask: true,
                    duration: 1000
                })
                return
            }
            if (!this.organize.mobilePhone) {
                wx.showToast({
                    title: '请输入手机号码',
                    icon: 'none',
                    mask: true,
                    duration: 1000
                })
                return
            }
            if (!this.organize.password) {
                wx.showToast({
                    title: '请输入初始密码',
                    icon: 'none',
                    mask: true,
                    duration: 1000
                })
                return
            }
            this.organize.parentId = this.addSubChooseInfo.F_Id
            addOrganize(this.organize)
                .then((res) => {
                    console.log(res)
                    this.$store.commit('org/SETADDSUBCHOOSEINFO', {})
                    wx.showToast({
                        title: '添加成功',
                        icon: 'none',
                        mask: true
                    })
                    wx.navigateBack({
                        delta: 1
                    })
                })
        },
        chooseDep () {
            const url = '/pages/center/chooseDepartment?type=addSub'
            wx.navigateTo({ url })
        }
    },
    computed: {
        ...mapState({
            addSubChooseInfo: state => state.org.addSubChooseInfo
        })
    },

    mounted () {
        console.log(this.$root.$mp)
    },

    async onShow () {
        console.log(this.addSubChooseInfo)
    }
}
</script>

<style lang='stylus' scoped>
.addDepartment
    width 750rpx
    padding-top 15rpx
    min-height 98vh
    display flex
    flex-direction column
    justify-content space-between

</style>
